package com.salt.modules.sys.web;

import com.salt.common.json.AjaxJson;
import com.salt.core.web.BaseController;
import com.salt.modules.sys.entity.AuthUser;
import com.salt.modules.sys.service.AuthUserService;
import com.salt.modules.sys.utils.UserUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;


/**
 * (EditionFiles)表控制层
 *
 * @author makejava
 */
@Api(tags = "版本更新信息")
@RestController
@CrossOrigin
@RequestMapping("sys/doc/user")
public class AuthUserController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private AuthUserService authUserService;



    /**
     * 添加新用户
     *
     * @return 单条数据
     */
    @ApiOperation(value = "添加新用户")
    @PostMapping("add")
    public AjaxJson insert() {
        AuthUser user = new AuthUser();

        user.setUsername(UserUtils.getUser().getLoginName());
        user.setPassword("123456");

        user.setIsStaff(0);
        user.setIsSuperuser(0);
        user.setIsActive(1);

        user.setFirstName(UserUtils.getUser().getName());
        user.setLastName("");
        user.setDateJoined(new Date());

        authUserService.insert(user);

        return AjaxJson.success().put("username", user.getUsername());
    }
}